/**   
* @Title: SessionController.java
* @Package me.cloud
* @Description: TODO
* @author xaoyaoyao
* @date Dec 21, 2018 2:43:34 PM
* @version V1.0   
*/
package me.cloud.controller;

import java.util.Collections;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: SessionController
 * @Description: TODO
 * @author xaoyaoyao
 * @date Dec 21, 2018 2:43:34 PM
 * 
 */
@RestController
@RefreshScope
public class SessionController {

	@GetMapping("/user")
	@ResponseBody
	public Object getUser(HttpServletRequest request) {
		HttpSession session = request.getSession();
		String username = (String) session.getAttribute("username");
		if (StringUtils.isEmpty(username)) {
			session.setAttribute("username", "testSessionRedis|" + System.currentTimeMillis());
		}
		return Collections.singletonMap("username", username);
	}

}